package com.CityHunter.Request;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

import android.util.Log;

import com.CityHunter.Common.Http;


public class GetBuddyIdRequest {

	private String getBuddyIdPage;

	public GetBuddyIdRequest(String getBuddyIdPage) {
		this.getBuddyIdPage = getBuddyIdPage;
	}

	public int getBuddyId(String email) {
		
		int buddyid = 0;
		
		// Declare NameValuePair to store the data
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("email", email));

		// Send Get Buddy ID Request
		Http http = new Http();
		Log.d("abdy_Debug", "Sending Request : " + getBuddyIdPage);
		JSONArray jsonResponse = http.sendRequest(getBuddyIdPage, params);
		try {
			buddyid = Integer.parseInt(jsonResponse.getJSONObject(0)
					.getString("buddyid"));
			Log.d("abdy_Debug", "Response BuddyID : " + buddyid);
		} catch (Exception e) {
			Log.e("abdy_Error", e.getMessage().toString());
		}
		
		return buddyid;
	}

}
